import random
import turtle

# 设置画布大小和背景色
turtle.setup(800, 600)
turtle.bgcolor('black')

# 定义画笔
pen = turtle.Turtle()
pen.hideturtle()
pen.speed(0)
pen.pensize(3)

# 定义星星半径和颜色列表
star_radius = [1, 2, 3]
star_colors = ['white', 'yellow']


# 定义星星生成函数
def create_star():
    x = random.randint(-300, 300)
    y = random.randint(-200, 200)
    radius = random.choice(star_radius)
    color = random.choice(star_colors)
    pen.penup()
    pen.goto(x, y)
    pen.pendown()
    pen.dot(radius, color)


# 定义流星生成函数
def create_meteor():
    x = random.randint(-300, 300)
    y = random.randint(-200, 200)
    length = random.randint(50, 100)
    speed = random.randint(5, 10)
    pen.penup()
    pen.goto(x, y)
    pen.pendown()
    pen.pencolor('white')
    pen.forward(length)
    pen.backward(length / 2)
    pen.right(120)
    pen.forward(length / 3)
    pen.left(120)
    pen.forward(length / 3)
    pen.backward(length / 2)
    pen.pencolor('yellow')
    pen.forward(length / 3)
    pen.backward(length / 3)
    pen.left(120)
    pen.forward(length / 3)
    pen.right(120)


# 生成星星和流星
for i in range(50):
    create_star()

for i in range(10):
    create_meteor()

# 定义动画循环
while True:
    # 移动流星
    for i in range(10):
        pen.penup()
        pen.setposition(random.randint(-300, 300), random.randint(-200, 200))
        pen.pendown()
        pen.clear()
        create_meteor()
    # 生成新星
    for i in range(5):
        create_star()
    turtle.update()